<template>
  <svg v-if="iconClass" :type="type" :class="svgClass" aria-hidden="true">
    <use :xlink:href="iconClass"></use>
  </svg>
</template>

<script>
export default {
  name: "SvgClass",
  data() {
    return {
    }
  },
  created() {
  },
  props: {
    //  使用icon的图标类型
    type: {
      type: String,
      required: true,
    },
    // 是否添加class样式
    className: {
      type: String,
      default: ""
    }
  },
  computed: {
    iconClass() {
      return `#icon-${this.type}`
    },
    svgClass() {
      if (this.className) {
        return `icon ${this.className}`
      } else {
        return "icon"
      }
    }
  }
}
</script>

<style type="text/css" scoped>
.icon {
  width: 1em;
  height: 1em;
  vertical-align: -0.15em;
  fill: currentColor;
  overflow: hidden;
}
</style>
